; chapter3 exercise 3
(setf L '(a b a d a c d c a))


(defun occurrences (lst)
	(let ((kv nil))
		(dolist (u (distinct lst))
			(let ((cnt 0))
				(dolist (obj lst)
					(if (eql u obj)
						(setf cnt (+ 1 cnt))))
				(setf kv (append kv (list (cons u cnt))))))
		(sort kv #'assoc-compr)))


(defun assoc-compr (o1 o2)
	(> (cdr o1) (cdr o2)))



(defun distinct (lst)
	(let ((unique nil))
		(dolist (obj lst)
			(setf unique (adjoin obj unique)))
		unique))
